package math.vectorSpace.R3.object;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.QuadCurve2D;

import math.vectorSpace.R2.Point2D;
import math.vectorSpace.R3.Point3D;
import math.vectorSpace.R3.Vector3D;
import math.vectorSpace.R3.visualization.RenderOrthographic;
import math.vectorSpace.R3.visualization.Render3D;
import math.vectorSpace.R3.visualization.VisualizationProperties;

public class Jet extends MovableObject {

    public Jet(Point3D center) {
        totalPts = 26;
        this.center = center;
        v = new Vector3D[totalPts];

        // Head
        v[0] = new Vector3D(0, 9, 0);

        // Tail
        v[1] = new Vector3D(0, -5, 0);

        // Control Points
        v[2] = new Vector3D(2.5, 4, 0);
        v[3] = new Vector3D(-2.5, 4, 0);

        // Head
        v[4] = new Vector3D(0, 9, 0);

        // Tail
        v[5] = new Vector3D(0, -5, 0);

        // Control Points
        v[6] = new Vector3D(0, 4, 1.05);
        v[7] = new Vector3D(0, 4, -1.05);

        // Left
        v[8] = new Vector3D(1, 4, 0);

        // Right
        v[9] = new Vector3D(-1, 4, 0);

        // Control Points
        v[10] = new Vector3D(0, 4, 1);
        v[11] = new Vector3D(0, 4, -1);

        // Right wing
        v[12] = new Vector3D(0.8, 1, 0);
        v[13] = new Vector3D(4, -3, 0);
        v[14] = new Vector3D(4.2, -3.8, 0);

        // Left wing
        v[15] = new Vector3D(-4.2, -3.8, 0);
        v[16] = new Vector3D(-4, -3, 0);
        v[17] = new Vector3D(-0.8, 1, 0);

        // Right fin
        v[18] = new Vector3D(3.5, -2.5, 0);
        v[19] = new Vector3D(3.5, -4, 0);
        v[20] = new Vector3D(3.5, -4, 1.5);
        v[21] = new Vector3D(3.5, -2.8, 1.5);


        // Left fin
        v[22] = new Vector3D(-3.5, -2.5, 0);
        v[23] = new Vector3D(-3.5, -4, 0);
        v[24] = new Vector3D(-3.5, -4, 1.5);
        v[25] = new Vector3D(-3.5, -2.8, 1.5);
    }

    @Override
    public void draw(Render3D display, Graphics2D g, 
    VisualizationProperties properties) {
        Point2D[] rendered = new Point2D[totalPts];
        for (int i = 0; i < v.length; i++) {
            rendered[i] = display.project(center.add(v[i]));
        }

        Polygon wing = new Polygon();
        for (int i = 12; i < 18; i++) {
            addPoint(wing, rendered[i]);
        }
        g.setColor(new Color(0.0f, 0.0f, 0.0f));
        g.fill(wing);

        g.setColor(new Color(0.3f, 0.1f, 0.1f));

        QuadCurve2D curve = new QuadCurve2D.Double(rendered[0].getX(), rendered[0].getY(),
                rendered[2].getX(), rendered[2].getY(), rendered[1].getX(), rendered[1].getY());
        g.fill(curve);
        curve.setCurve(rendered[0].getX(), rendered[0].getY(), rendered[3].getX(), rendered[3].getY(),
                rendered[1].getX(), rendered[1].getY());
        g.fill(curve);

        curve = new QuadCurve2D.Double(rendered[4].getX(), rendered[4].getY(), rendered[6].getX(),
                rendered[6].getY(), rendered[5].getX(), rendered[5].getY());
        g.fill(curve);
        curve.setCurve(rendered[4].getX(), rendered[4].getY(), rendered[7].getX(), rendered[7].getY(),
                rendered[5].getX(), rendered[5].getY());
        g.fill(curve);

        curve = new QuadCurve2D.Double(rendered[8].getX(), rendered[8].getY(), rendered[10].getX(),
                rendered[10].getY(), rendered[9].getX(), rendered[9].getY());
        g.fill(curve);
        curve.setCurve(rendered[8].getX(), rendered[8].getY(), rendered[11].getX(), rendered[11].getY(),
                rendered[9].getX(), rendered[9].getY());
        g.fill(curve);

        Polygon fin = new Polygon();
        g.setColor(new Color(0.5f, 0.1f, 0.1f));

        for (int i = 18; i < 22; i++) {
            addPoint(fin, rendered[i]);
        }
        g.fill(fin);

        fin = new Polygon();
        for (int i = 22; i < 26; i++) {
            addPoint(fin, rendered[i]);
        }
        g.fill(fin);

    }
}
